package com.ease.framework.gef4p.figures.impl {
   import com.ease.framework.figures.IFigure;
   import com.ease.framework.gef4p.figures.ILabelFigure;
   import com.ease.framework.gef4p.figures.ILabelFigureBox;
   
   import mx.containers.Canvas;
   import mx.controls.Label;
   import mx.controls.Text;

   public class LabelFigure extends Canvas implements ILabelFigure {
      //private var _contentLabelShow:TextArea = new TextArea();

      private var _container:ILabelFigureBox;
      private var _isSelected:Boolean;

      private var _text:String;
      private var _label:Text;

      private var _editX:Number = 0;
      private var _editY:Number = 0;
      private var _editWidth:Number = 0;
      private var _editHeight:Number = 0;

      private var _isWidthLimited:Boolean = false;

      public function LabelFigure() {
         super();
         this.setStyle("backgroundAlpha", "0");
         this.setStyle("borderStyle", "none");
         horizontalScrollPolicy = "off";
         verticalScrollPolicy = "off";
         clipContent = false;

         this._label = new Text();
         this._label.text = this.text;
         this.addChild(_label);
      }

      public function getContainer():ILabelFigureBox {
         return _container;
      }

      public function setContainer(box:ILabelFigureBox):void {
         _container = box;
      }

      public function get isWidthLimited():Boolean {
         return _isWidthLimited;
      }

      public function set isWidthLimited(value:Boolean):void {
         _isWidthLimited = value;
      }

      public function set text(t:String):void {
         //super.text = t;
         //this.refreash();
         _text = t;
         _label.text = t;
         invalidateDisplayList();
      }

      public function get text():String {
         return _text;
      }

      public function getTextWidth():Number {
         return this._label.textWidth;
      }

      public function getTextHeight():Number {
         return this._label.height;
      }

      public function findFigureAt(stageX:Number, stageY:Number):IFigure {
         return this;
      }

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
         super.updateDisplayList(unscaledWidth, unscaledHeight);
            width = getTextWidth() + 2;
            height = getTextHeight(); 
            if (isSelected)
               this.width = this._label.width + 2;
            if (isWidthLimited && getContainer() != null) {
               this._label.maxWidth = getContainer().width;
            }
      }

      public function get editX():Number {
         return _editX;
      }

      public function set editX(n:Number):void {
         _editX = n;
      }

      public function get editY():Number {
         return _editY
      }

      public function set editY(n:Number):void {
         _editY = n;
      }

      public function get editWidth():Number {
         return _editWidth;
      }

      public function set editWidth(n:Number):void {
         _editWidth = n;
      }

      public function get editHeight():Number {
         return _editHeight;
      }

      public function set editHeight(n:Number):void {
         _editHeight = n;
      }

      public function refreash():void {
         this.toolTip = this.text;
      }

      public function get isSelected():Boolean {
         return _isSelected;
      }

      public function set isSelected(value:Boolean):void {
         _isSelected = value;
         if (value) {
            this.setStyle("borderStyle", "solid");
         }
         else {
            this.setStyle("borderStyle", "none");
         }
      }

   }
}